/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package common;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

/**
 *
 * @author Jhonny
 */
public class ArticuloConverter implements Converter {

    @Override
    public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
        System.out.println("");
        /*Person person = (Person) value;
                writer.startNode("fullname");
                writer.setValue(person.getName());
                writer.endNode();
         *
         */
    }

    @Override
    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
        Articulo articulo = null;
        if(context.getRequiredType()==Ropa.class){
            articulo = new Ropa();
            reader.moveDown();
            if(reader.getNodeName()!=null && reader.getNodeName().equalsIgnoreCase("referencia")){
                articulo.setReferencia(Integer.valueOf(reader.getValue()));
            }
            reader.moveUp();
            
        }
        return articulo;
    }

    @Override
    public boolean canConvert(Class type) {
        boolean convertir=false;
        if(type== Ropa.class || type == Hogar.class){
            convertir=true;
        }
        return convertir;
    }

}
